Skip to content

Conversation

chensunny
Copy link

summy

This pull request updates the behavior of the HTTP library to handle cases where the request body is nil for methods that expect a body (e.g., POST, PUT, PATCH). It introduces an error message for such cases and adjusts the corresponding tests to align with the new behavior.

Related issues

closed #331

Changes to HTTP request handling:

  • lib/resty/http.lua: Updated the _M.send_request function to return an error when the request body is nil for methods that expect a body. The error message advises using an empty string ("") if an empty body is intended.

Changes to tests:

  • t/06-simpleinterface.t: Modified test 7 to explicitly set the request body to an empty string ("") for POST, PUT, and PATCH requests, ensuring the Content-Length header is correctly set.
  • t/06-simpleinterface.t: Added a new test (test 9) to verify that an error is returned when the request body is nil for POST, PUT, and PATCH requests. This test confirms the new behavior and validates the error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If the Post the body is nil, will get unexpected error
1 participant